package com.apabi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.apabi.common.pojo.JqGridResult;
import com.apabi.mapper.SysTokenMapper;
import com.apabi.pojo.SysToken;
import com.apabi.service.SysTokenService;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhangxh.apabi on 2017/9/22.
 */
@Service
public class SysTokenServiceImpl implements SysTokenService{


    @Autowired
    private SysTokenMapper sysTokenMapper;

    @Autowired
    private Sid sid;

    @Override
    public void saveSysToken(SysToken sysToken) {
        String itemId = sid.nextShort();
        sysToken.setId(itemId);
        sysTokenMapper.insert(sysToken);
    }

    @Override
    public JqGridResult querySysTokenList(String name, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<SysToken> list =  sysTokenMapper.selectAll();
        PageInfo<SysToken> pageList = new PageInfo<SysToken>(list);

        JqGridResult grid = new JqGridResult();
        grid.setTotal(pageList.getPages());
        grid.setRows(list);
        grid.setPage(pageList.getPageNum());
        grid.setRecords(pageList.getTotal());
        return grid;
    }

    @Override
    public SysToken querySysTokenById(String sysTokenId) {
        return sysTokenMapper.selectByPrimaryKey(sysTokenId);
    }

    @Override
    public void deleteSysTokenById(String sysTokenId) {
        sysTokenMapper.deleteByPrimaryKey(sysTokenId);
    }

    @Override
    public void updateSysTokenById(SysToken sysToken) {
        sysTokenMapper.updateByPrimaryKey(sysToken);
    }

    @Override
    public List<SysToken> queryAllSysTokenList() {
        return sysTokenMapper.selectAll();
    }
}
